
$(function(){
	$('.validate').checkForm();
	//$('.area_selector').autoCity();

	// msg switcher
	switchMsg();

	// auto complete
	var availableTags = '/index.php?app=home&mod=Public&act=district';
	$( ".district" ).autocomplete({
		source: availableTags,
		minLength: 1,
		search: function(event, ui) {
			var _cid = $('.area_selector select:last').val();
			if (_cid == '-1') {
				return false;
			} else {
				var tmp = availableTags + '&country_id=' + _cid;
				$(".district" ).autocomplete('option','source', tmp);
				return true;
			}
		}
	});
	/*$('.area_selector select:last').change(function(){
		$( ".district" ).val('');
	});*/

	// date selector
	$(".date_selector").datepicker(
		{
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin : ['一', '二','三', '四', '五', '六', '日'] ,
			yearSuffix: '年',
			dateFormat: 'yy-mm-dd',
			showAnim: 'fold',
			defaultDate: -1095,
			changeYear: true
		 }
	);

});

function switchMsg()
{
	$('.intro .buttons a').each(function(){
		$(this).mouseover(function(){
			var posLeft = $(this).offset().left+$(this).width()/2,
				desClass = '.' + $(this).attr('class') + '_msg';
			$('.info .arrow').offset({left: posLeft-12});
			$('.info p:visible').fadeOut(function(){$(desClass).fadeIn()});;
		});
	})
}


//选择生日
function selectMonth(){
	var Year = $('#birthday_year').val();
	var Month = $('#birthday_month').val();
	var monthDay   =  new  Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var monthDayNum;
	if(Year%400==0||(Year%4==0&&Year%100!=0)) monthDay[1]=   29;
	monthDayNum   =   monthDay[Month-1];

	var i;
	var daysout = '';
	for(i=1;i<=monthDayNum;i++){
		daysout+='<option value='+i+'>'+i+'</option>';
	}
	$('#birthday_day').html(daysout);
}

function insert_birth(){
	$("#birthday").removeClass("errorInput");
	$(".error_birthday").hide();
	$("#success_birthday").show();
}

function areaopt_plugin_fun(){
	$("#areaval").removeClass("errorInput");
	$(".error_areaval").hide();
	$("#success_areaval").show();
}
function work_check(){
	$("#school_check").hide();
	$("#school_name").val("null");
	if($("#work_name").val() == "null") $("#work_name").val("");
	$("#work_check").show();
}
function school_check(){
	$("#work_check").hide();
	$("#work_name").val("null");
	if($("#school_name").val() == "null") $("#school_name").val("");
	$("#school_check").show();
}
function other_check(){
	$(".the_check").hide();
	$("#work_name").val("null");
	$("#school_name").val("null");
}

function service_dialog(){

	ymPrompt.win({message:APP+'/Information/service',width:600,height:290,title:'服务条款',iframe:true})
}



//用户资料编辑
$(document).ready(function() {
    $('#form1').checkForm();
    $('#form1').submit(function() {
        if($('.error_tips:visible')) {
            var options = {
                //beforeSubmit:  $('.validate').checkForm(),  // pre-submit callback
                success:       showResponse,  // post-submit callback
                type:      'post',        // 'get' or 'post', override for form's 'method' attribute
                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type)
            };
            $(this).ajaxSubmit(options);
        }
        return false;
    });

    $('#form2').checkForm();
    $('#form2').submit(function() {
        if($('.error_tips:visible')) {
            var options = {
                //beforeSubmit:  $('.validate').checkForm(),  // pre-submit callback
                success:       showResponse,  // post-submit callback
                type:      'post',        // 'get' or 'post', override for form's 'method' attribute
                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type)
            };
            $(this).ajaxSubmit(options);
        }
        return false;
    });

    $('#form3').checkForm();
    $('#form3').submit(function() {
        if($('.error_tips:visible')) {
            var options = {
                //beforeSubmit:  $('.validate').checkForm(),  // pre-submit callback
                success:       showResponse,  // post-submit callback
                type:      'post',        // 'get' or 'post', override for form's 'method' attribute
                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type)
            };
            $(this).ajaxSubmit(options);
        }
        return false;
    });

    $('#form4').checkForm();
    $('#form4').submit(function() {
        if($('.error_tips:visible')) {
            var options = {
                //beforeSubmit:  $('.validate').checkForm(),  // pre-submit callback
                success:       showResponse,  // post-submit callback
                type:      'post',        // 'get' or 'post', override for form's 'method' attribute
                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type)
            };
            $(this).ajaxSubmit(options);
        }
        return false;
    });

    $('#family').checkForm();
    $('#family').submit(function() {
        if($('.error_tips:visible')) {
            var options = {
                //beforeSubmit:  $('.validate').checkForm(),  // pre-submit callback
                success:       showResponse,  // post-submit callback
                type:      'post',        // 'get' or 'post', override for form's 'method' attribute
                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type)
            };
            $(this).ajaxSubmit(options);
        }
        return false;
    });
});

//用户资料编辑，AJAX响应处理
function showResponse(responseText, statusText)  {
    if (responseText.status) {
        ui.success(responseText.info);
    } else {
        ui.error(responseText.info);
    }
}